package com.tianqu.tms.www.car.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.dto.MarketCarInfoDto;
import com.tianqu.tms.entity.Car;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class CarMarketInCityListAjaxAction extends TmsAjaxAction {
	@Override
	public void process(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response, UserContext uc) throws TmsException {
		String query = request.getParameter("query");
		List<HashMap> r = new ArrayList();
		List<MarketCarInfoDto> list = Car.getInstance().getVaoNameInfoList(query);
		for (MarketCarInfoDto marketCarInfoDto : list) {
			HashMap map = new HashMap();
			map.put("value", marketCarInfoDto.getVaoName());
			map.put("data", marketCarInfoDto.getCityId());
			r.add(map);
		}
		JSONArray jsonArray = JSONArray.fromObject(JSONArray.fromObject(r));
		JSONObject json = new JSONObject();
		json.put("query", query);
		json.put("suggestions", jsonArray);
		responseValues(response, json.toString(), TEXT);
	}
}
